import format from '@dfeidao/atom-web/dt/format';
import parse from '@dfeidao/atom-web/dt/parse';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p004 from './p004';
import p005 from './p005';
import p007 from './p007';

export default async function a005(fd: IFeidaoAiBrowserComponent) {
	// todo
	// 查询我的会议列表
	const staff_no = get('staff_no');
	const n = fd.data.node.querySelector<HTMLInputElement>('[data-id="conference_theme1"]').value;
	// 时间格式
	const ch_sj = fd.data.node.querySelector<HTMLDataElement>('[data-id="ch"]').value;
	const ks = parse(ch_sj);
	const js_sj = fd.data.node.querySelector<HTMLDataElement>('[data-id="ch1"]').value;
	const js = parse(js_sj);
	if (ks > js) {
		alert('开始时间不能大于结束时间');
		return;
	}
	const res = await nodejs<{ res: Array<{ meeting_no: string, meeting_name: string, start_time: number, conference_theme: string, meeting_status: string, sponsor: string, meeting_address: string }>; s: Array<{}> }>('meeting-management/zj-000001/s006', {
		staff_no,
		conference_theme: n,
		start_time: ks,
		start_time1: js,
		pn:1
	});
	for (let j = 0; j < res.res.length; j++) {
		if (res.res[j].meeting_status === "1") {
			res.res[j].meeting_status = '进行中';
		} else if (res.res[j].meeting_status === "2") {
			res.res[j].meeting_status = '未解决';
		} else if (res.res[j].meeting_status === "3") {
			res.res[j].meeting_status = '完成';
		}}
	// tslint:disable-next-line:no-shadowed-variable
	const d = res.res.map((n) => {
		// 0 不显示时分秒 1 显示秒  2 不显示秒
		return { ...n, start_time: format(n.start_time, 0) };
	});
	const dtNO = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p004"]');
	const dtH = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	const dts = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p007"]');
	if (res.s.length > 0) {
		render(fd, d, p004, 'p004', 'inner');
		dtNO.style.display = 'block';
		dtH.style.display = 'none';
	} else {
		render(fd, '', p005, 'p005', 'inner');
		dtNO.style.display = 'none';
		dtH.style.display = 'block';
	}
	if (d.length > 20) {
		render(fd, res.s.length, p007, 'p007', 'inner');
		dts.style.display = "block";
	}

}
